﻿using Collections.Pooled;
using furion.blog.Application.Contracts;
using furion.blog.Application.CustomMapper;
using furion.blog.Domain.IRepositories;
using furion.blog.Domain.MySQL;
using furion.blog.Domain.Shared.Dto.Menu;
using Furion.DependencyInjection;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace furion.blog.Application;

public class SystemService : ISystemService, ITransient
{
    public readonly IMenuRepository _menuRepository;
    public readonly MenuMapper _menuMapper;

    public SystemService(IMenuRepository menuRepository,MenuMapper menuMapper) {
        this._menuRepository = menuRepository;
        this._menuMapper = menuMapper;
    }

    public string GetDescription()
    {
        return "让 .NET 开发更简单，更通用，更流行。";
    }


    /// <summary>
    /// 同步菜单
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    public async Task SyncMenus(List<MenuTreeNodeDto> data) {
        this._menuRepository.Truncate();
        List<Menu> saves = new List<Menu>();
        data.ForEach(x => {
            saves.Add(this._menuMapper.Map(x,new Menu()));
        });
        await this._menuRepository.Save(saves);
    }

}
